﻿var whoever = new Whoever();

function Whoever() {
    var selfWhoever = this;

    selfWhoever.GetBy = function (list, key, value) {
        return $.grep(list, function (item) {
            if (item[key]() == value)
                return item;
        });
    }

    selfWhoever.EmailIsValid = function (value) {
        var sQtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
        var sDtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
        var sAtom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
        var sQuotedPair = '\\x5c[\\x00-\\x7f]';
        var sDomainLiteral = '\\x5b(' + sDtext + '|' + sQuotedPair + ')*\\x5d';
        var sQuotedString = '\\x22(' + sQtext + '|' + sQuotedPair + ')*\\x22';
        var sDomain_ref = sAtom;
        var sSubDomain = '(' + sDomain_ref + '|' + sDomainLiteral + ')';
        var sWord = '(' + sAtom + '|' + sQuotedString + ')';
        var sDomain = sSubDomain + '(\\x2e' + sSubDomain + ')*';
        var sLocalPart = sWord + '(\\x2e' + sWord + ')*';
        var sAddrSpec = sLocalPart + '\\x40' + sDomain; // complete RFC822 email address spec
        var sValidEmail = '^' + sAddrSpec + '$'; // as whole string

        var reValidEmail = new RegExp(sValidEmail);

        if (value && value != "")
            if (reValidEmail.test(value))
                return true;
            else
                return false;
        else
            return true;
    }

    selfWhoever.IsEmpty = function (value) {
        return ($.trim(value) ? false : true)
    }

    selfWhoever.main = function () {
        var main = $(".main");
        if (!main) console.log("Container with class main must be added");
        return main;
    }

    selfWhoever.MainExitLeft = function () {
        var newLeft = $(window).width() * -1;
        var move = $.when(selfWhoever.main().stop().animate({ left: newLeft }));

        return move;
    }

    selfWhoever.MainExitRight = function () {
        var newLeft = $(window).width();
        var move = $.when(selfWhoever.main().stop().animate({ left: newLeft }));

        return move;
    }

    selfWhoever.MainEnter = function () {
        var move = $.when(selfWhoever.main().stop().animate({ left: 0 }));

        return move;
    }

    selfWhoever.MainHidden = function () {
        selfWhoever.main().css("display", "none");
    }

    selfWhoever.MainVisible = function () {
        selfWhoever.main().css("display", "");
    }

    selfWhoever.MainRight = function () {
        var newLeft = $(window).width();
        selfWhoever.main().css("left", newLeft);
    }

    selfWhoever.MainLeft = function () {
        var newLeft = $(window).width() * -1;
        selfWhoever.main().css("left", newLeft);
    }

    selfWhoever.DisableAll = function () {
        $("input").attr("disabled", "disabled");
        $("select").attr("disabled", "disabled");
        $("button").attr("disabled", "disabled");


    }

    selfWhoever.EnableAll = function () {
        $("input").removeAttr("disabled");
        $("select").removeAttr("disabled");
        $("button").removeAttr("disabled");
    }

    selfWhoever.DisableButtons = function () {
        $("button").attr("disabled", "disabled");
    }

    selfWhoever.EnableButtons = function () {
        $("button").removeAttr("disabled");
    }
}